import type { App } from "vue";
import { createI18n, VueI18nTranslation } from "vue-i18n";

type Locale = {
  [key: string]: string | Locale;
};

type LocaleLoaders = {
  [key: string]: () => Promise<{ default: Locale } | null>;
};

export const i18n = createI18n({
  locale: "en",
  fallbackLocale: "en",
});

export const $t: VueI18nTranslation = i18n.global.t;

export const $$t: VueI18nTranslation = i18n.global.t;

export async function useI18n(app: App, en: Locale, loaders: LocaleLoaders) {
  i18n.global.locale = "zh";
  app.use(i18n);
  i18n.global.mergeLocaleMessage("zh", en);
}
